<link rel="stylesheet" type="text/css" href="../static/Huploadify-master/Huploadify.css">
<script type="text/javascript" src="../static/Huploadify-master/jquery.Huploadify.js"></script>
<style>
    li {
        list-style-type: none;
        vertical-align: middle;
        height: 30px;
        line-height: 30px;
        margin: 10px 0;
    }
    li a{text-decoration:none;}
    li a img{
        border:1px solid #999999;
        margin-right: 20px;
        float: left
    }
    li a div{
        float: left;
        width: 50%;
        text-align: center;
        height: 30px;
        line-height: 30px;
        vertical-align: middle;
        white-space:nowrap;
        overflow:hidden;
        text-overflow:ellipsis;
    }
    li a div{
        width:50%;
        text-align: center;
    }

</style>
<script type="text/javascript">

    $(function () {

        $("#keyId").val(getUrlParam("keyId", url));

        $("#datagrid").datagrid({ pagination: true,
            url:'',
            method: 'POST',
            <!--loadFilter:pagerFilter,-->
            queryParams:{},
            toolbar:"#toolbar",
            rownumbers:true,
            pagination:false,
            columns: [[
                {field : 'id',title : '编号',checkbox : true},
                { field: 'code', title: '公司代码', width:50,align:'center'},
                { field: 'name', title: '公司名称', width: 100,align:'center'}
            ]],
            fitColumns:true　//自适应宽度、可以水平滚动
        });

        $("#schbt").click(function () {
            showLoading();
            $.ajax({
                type: 'POST',
                url: '../controller/deliverGoodsWebSet/getWeb.do?RndId='+Math.random(),
                data: {"companyCode":$("#keyId").val()},
                success: function(data){
                    hideLoading();
                    if (!isSuccess(data)) {
                        $.messager.alert('系统提示', data.msg, 'error', function () {
                            self.focus();
                        });
                    } else {
                        var childWeb = data.content.childWeb;
                        var web = data.content.web;
                        $("#datagrid").datagrid('loadData', childWeb);
                        for (var i = 0; i < childWeb.length; ++i){
                            if (childWeb[i].useFlag == 1){
                                $("#datagrid").datagrid('selectRow',i);
                            }
                        }
                        if (web != null){
                            $("#companyInfo").html("<table><tr><td>总代码：</td><td>"+web.code+"</td></tr>" +
                                "<tr><td>总名称：</td><td>"+web.name+"</td></tr></table>");
                            $("#companyCode").val(web.code);
                        } else {
                            $("#companyInfo").empty();
                            $("#companyCode").val("");
                        }
                    }
                },
                error: function(){
                    hideLoading();
                    $.messager.alert('系统提示', "网络异常，请尝试刷新页面", 'error', function () {
                        self.focus();
                    });
                },
                dataType: 'json'
            });

        });
        $("#schbt").click();

        $("#rstbt").click(function () {
            console.log("重置");//将Form中的数据清空即可

            $("#schForm :input")
                .not(':button, :submit, :reset, :hidden')
                .val('')
                .removeAttr('checked')
                .removeAttr('selected');
        });

        $("#btnSave").click(function () {
            var rows = $('#datagrid').datagrid('getSelections');
            console.log(rows);
            if (rows == null || rows.length == 0){
                $.messager.alert('系统提示', "没有选择数据，不能进行提交操作", 'error', function () {
                    self.focus();
                });
               return;
            }
            var childCodes = '';
            for (var i = 0; i < rows.length; ++i){
                childCodes += rows[i].code + ",";
            }
            $("#btnSave").blur();
            showLoading();
            $.ajax({
                type: 'POST',
                url: '../controller/deliverGoodsWebSet/save.do?RndId='+Math.random(),
                data: {"companyCode":$("#companyCode").val(),"childCodes":childCodes},
                success: function(data){
                    hideLoading();
                    if (!isSuccess(data)) {
                        $.messager.alert('系统提示', data.msg, 'error', function () {
                            self.focus();
                        });
                    } else {
                        $.messager.alert('系统提示', data.msg, 'success', function () {
                            self.focus();
                        });
                    }
                },
                error: function(){
                    hideLoading();
                    $.messager.alert('系统提示', "网络异常，请尝重新提交", 'error', function () {
                        self.focus();
                    });
                },
                dataType: 'json'
            });
        });
    });
    function turnBack() {
        parent.j_closeWin();
    }
</script>

<body class="easyui-layout">
<div data-options="region:'north',title:'查询'" border="false" style="height: 40px" class="datagrid-toolbar">
    <form id="schForm" method="post">
        <table>
            <tr>
                <th>总代码：</th>
                <td>
                    <input type="text" class="easyui-textbox" id="keyId" name="companyCode"/>
                    <a href="#" id="schbt" class="easyui-linkbutton">查询</a>
                    <a href="#" id="rstbt" class="easyui-linkbutton">重置</a>
                </td>
            </tr>
        </table>
    </form>
</div>
<div data-options="region:'center'" fit="true" border="false">
    <table id="datagrid"></table>
</div>
</body>
<div id="toolbar" style="font-size:16px;">
    <div id="companyInfo"></div>
    <input type="hidden" id="companyCode" value=""/>
    <a href="#" id="btnSave" style="border-radius: 4px;background-color: #4CAF50;border: none;color: white;padding: 7px 15px;text-align: center;text-decoration: none;display: inline-block;font-size: 16px;margin: 4px 2px;cursor: pointer;">提交</a>
</div>